package com.ruoyi.device.service.impl;

import java.util.List;
import com.ruoyi.common.core.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.device.mapper.AlarmRuleMapper;
import com.ruoyi.device.domain.AlarmRule;
import com.ruoyi.device.service.IAlarmRuleService;

import static com.ruoyi.common.security.utils.SecurityUtils.getLoginUser;

/**
 * 报警规则Service业务层处理
 * 
 * @author li
 * @date 2025-09-19
 */
@Service
public class AlarmRuleServiceImpl implements IAlarmRuleService 
{
    @Autowired
    private AlarmRuleMapper alarmRuleMapper;

    /**
     * 查询报警规则
     * 
     * @param id 报警规则主键
     * @return 报警规则
     */
    @Override
    public AlarmRule selectAlarmRuleById(Long id)
    {
        return alarmRuleMapper.selectAlarmRuleById(id);
    }

    /**
     * 查询报警规则列表
     * 
     * @param alarmRule 报警规则
     * @return 报警规则
     */
    @Override
    public List<AlarmRule> selectAlarmRuleList(AlarmRule alarmRule)
    {
        return alarmRuleMapper.selectAlarmRuleList(alarmRule);
    }

    /**
     * 新增报警规则
     * 
     * @param alarmRule 报警规则
     * @return 结果
     */
    @Override
    public int insertAlarmRule(AlarmRule alarmRule)
    {
        alarmRule.setCreateBy(getLoginUser().getUsername());
        alarmRule.setCreateTime(DateUtils.getNowDate());
        return alarmRuleMapper.insertAlarmRule(alarmRule);
    }

    /**
     * 修改报警规则
     * 
     * @param alarmRule 报警规则
     * @return 结果
     */
    @Override
    public int updateAlarmRule(AlarmRule alarmRule)
    {
        alarmRule.setUpdateBy(getLoginUser().getUsername());
        alarmRule.setUpdateTime(DateUtils.getNowDate());
        return alarmRuleMapper.updateAlarmRule(alarmRule);
    }

    /**
     * 批量删除报警规则
     * 
     * @param ids 需要删除的报警规则主键
     * @return 结果
     */
    @Override
    public int deleteAlarmRuleByIds(Long[] ids)
    {
        return alarmRuleMapper.deleteAlarmRuleByIds(ids);
    }

    /**
     * 删除报警规则信息
     * 
     * @param id 报警规则主键
     * @return 结果
     */
    @Override
    public int deleteAlarmRuleById(Long id)
    {
        return alarmRuleMapper.deleteAlarmRuleById(id);
    }
}
